window._MFN = {

    _STATUSLABEL_START_X:65,

    _STATUSLABEL_START_X_LEN:20,

    _LIGHTCONFIG:[
        [0,0,0,0,0],
        [1,0,0,0,0],
        [1,1,0,0,0],
        [1,1,1,0,0],
        [1,1,1,1,0],
        [1,1,1,1,1],
        [2,1,1,1,1],
        [2,2,1,1,1],
        [2,2,2,1,1],
        [2,2,2,2,1],
        [2,2,2,2,2],
    ],

    playerNodeTouch:function(){

        if(_FIGHT.funcType=="攻击"){

            _FIGHT.resetCmd();

            _FIGHT.isWaiting=false;

            _FIGHT.controllerLabel.active =false;

            var actioncmd={
                player:_FIGHT.doactionPlayer,
                target:this.player,
                type:'attack'
            };

            _FIGHT.fightLog(_FIGHT.doactionPlayer.name+"攻击"+this.player.name);

            _FIGHT.realDoAction(actioncmd);

        }else if(_FIGHT.funcType=="调查"){

            _MRDL.initUi(_FIGHT.node,{sence:_STYPE._FIGHTSENCE,
                                                        roleArr:this.player.isplayer?window.fightData.playerTeam:window.fightData.armyTeam,
                                                        roleIndex:this.player.teamIndex
                                                        });

            _FIGHT.resetCmd();
        }else if(_FIGHT.funcType=="技能"){

            var actioncmd={
                player:_FIGHT.doactionPlayer,
                targetArr:[this.player],
                type:'skill',
                skillName:_FIGHT.funcSkillorItem,
            };

            _FIGHT.resetCmd();

            _FIGHT.realDoAction(actioncmd);
        }else if(_FIGHT.funcType=="道具"){
            var actioncmd={
                player:_FIGHT.doactionPlayer,
                targetArr:[this.player],
                type:'item',
                itemName:_FIGHT.funcSkillorItem,
            };

            _FIGHT.resetCmd();

            _FIGHT.realDoAction(actioncmd);
        }

    },


    refreshPlayerNode:function(playerNode,player){
        var playerRole = playerNode.getChildByName('role');
        _MFN.refreshPlayerInfo(playerNode,player);
        
        if(player.hp>0){
            playerRole.getComponent(cc.Animation).play('walk');
        }else{
            playerRole.getComponent(cc.Animation).play('weak');
        }
    },

    refreshEnergy:function(energy,player){

        var energyIndex = player.mg;

        if(!_MFN._LIGHTCONFIG[energyIndex]){
            energyIndex=0;
        }

        var lightConfig = _MFN._LIGHTCONFIG[energyIndex];

        for(var i=0;i<lightConfig.length;i++){

            var lightNode = energy.getChildren()[i];

            if(lightNode){

                if(lightConfig[i]==0){
                    lightNode.getChildByName('den_yellow').active = false;
                    lightNode.getChildByName('den_red').active = false;
                }else if(lightConfig[i]==1){
                    lightNode.getChildByName('den_yellow').active = true;
                    lightNode.getChildByName('den_red').active = false;
                }else if(lightConfig[i]==2){
                    lightNode.getChildByName('den_yellow').active = false;
                    lightNode.getChildByName('den_red').active = true;
                }

            }

        }
    },

    refreshPlayerInfo:function(playerNode,player){
        var playerInfo =  playerNode.getChildByName('info');
        var isPlayer = player.isplayer;
        var playerData = _ROLEDATA.getRoleDataOfPlayer(player);
        var statusInfo = _STATUSHELPERCHESS.getStatusForShow(player);
        
        var blood = playerInfo.getChildByName('blood');
        //var magic = playerInfo.getChildByName('magic');
        var energy = playerInfo.getChildByName('energy');
        var statusNode = playerInfo.getChildByName('status');

        blood.getComponent(cc.ProgressBar).progress = player.hp/playerData.maxHp;
        _MFN.refreshEnergy(energy,player);
        //energy.getComponent(cc.ProgressBar).progress = player.mg/playerData.maxMagic;
        //energy.getComponent(cc.ProgressBar).progress = player.eg/_CS.maxEnergy;

        if(isPlayer){
            //playerInfo.getChildByName('bianhao').getChildByName('mask_touxiang').color = new cc.color(_CS.bloodColor['player']);
            blood.getChildByName('bar').color = new cc.color(_CS.bloodColor['player']);
        }else{
            //playerInfo.getChildByName('bianhao').getChildByName('mask_touxiang').color = new cc.color(_CS.bloodColor['army']);
            blood.getChildByName('bar').color = new cc.color(_CS.bloodColor['army']);
        }

        playerInfo.getChildByName('bianhao').getChildByName('label')
        .getComponent(cc.Label).string = player.eg;

        if(statusInfo){
            //console.log('刷新状态',statusInfo);
            statusNode.active = true;
            statusNode.getChildByName('guan_touxian').color = new cc.color(statusInfo.color);
            statusNode.getChildByName('guan_touxian').getChildByName('label')
                        .getComponent(cc.Label).string = statusInfo.msg;
        }else{
            statusNode.active = false;
        }
        
    },

    createSignNode:function(player,statusObj){

        var key = statusObj.name;
        var nmb = statusObj.nmb;
        var node = _GRM.getNode('statusSign');

        if(!player.isplayer){
            node.setScale(-0.5,0.5);
        }else{
            node.setScale(0.5,0.5);
        }
        
        if(_STATUSCONF[key]){
            
            node.getChildByName('label').getComponent(cc.Sprite).spriteFrame = _GRM.getBuffFrame(_STATUSCONF[key].label);
            node.getChildByName('type').getComponent(cc.Label).string = _STATUSCONF[key].name;
            node.getChildByName('type').getComponent(cc.LabelOutline).color = new cc.color(_STATUSCOLORCONF[_STATUSCONF[key].label].word);
			if(key!='dang')
				node.getChildByName('nmb').getComponent(cc.Label).string = nmb;
			else
				node.getChildByName('nmb').getComponent(cc.Label).string = "";
            node.getChildByName('nmb').getComponent(cc.LabelOutline).color = new cc.color(_STATUSCOLORCONF[_STATUSCONF[key].label].nmb);
            
        }

        return node;

    },
    

    createPlayerNode:function(player,isPlayer){
        var playerLv = _EXPMANAGER.getLevelByExp(player.exp);

        var ftypeColor = _CS.ftype[player.ftype]?_CS.ftype[player.ftype].color:"#FFFFFF";

        var playerNodeObj = _GRM.getNodeObj('fighter');
        var playerNode = playerNodeObj.node;
            playerNode.isPlayer = isPlayer;
            playerNode.player = player;
        var playerRole = playerNode.getChildByName('role');
            //playerRole.setPosition(20,0);
			playerRole.stopAllActions();
            playerRole.setScale(-1,1);
        var playerInfo =  playerNode.getChildByName('info');
            playerInfo.active = true;
        //var playerbtn =  playerNode.getChildByName('btn');
        var selectedNode = playerNode.getChildByName('selected');
        var blood = playerInfo.getChildByName('blood');
        var aniObj = _GRM.getAttackFrame(player.pf);

        var aniArr = aniObj.walk;
        var attackAniArr = aniObj.attack;
        var weakAniArr = aniObj.weak;

        //playerInfo.getChildByName('bianhao').getChildByName('label')
        //.getComponent(cc.Label).string = player.code;

        playerInfo.getChildByName('bianhao').getChildByName('label')
        .getComponent(cc.Label).string = player.eg;

        playerInfo.getChildByName('bianhao').getChildByName('mask_touxiang').color 
        = new cc.color(ftypeColor);

        if(isPlayer){
            //playerInfo.getChildByName('bianhao').getChildByName('mask_touxiang').color = new cc.color(_CS.bloodColor['player']);
            blood.getChildByName('bar').color = new cc.color(_CS.bloodColor['player']);
        }else{
            //playerInfo.getChildByName('bianhao').getChildByName('mask_touxiang').color = new cc.color(_CS.bloodColor['army']);
            blood.getChildByName('bar').color = new cc.color(_CS.bloodColor['army']);
        }

        if(player.isboss){
            playerInfo.getChildByName('bianhao').getChildByName('boss').active = true;
        }else{
            playerInfo.getChildByName('bianhao').getChildByName('boss').active = false;
        }

        if(!isPlayer){
            //playerInfo.getChildByName('name').setScale(-1,1);
            //selectedNode.color = new cc.color("#61FF00");
            playerRole.setScale(1,1);
        }else{
            //playerInfo.getChildByName('name').setScale(1,1);
            //selectedNode.color = new cc.color("#FF0000");
            playerRole.setScale(-1,1);
        }

        playerNode.setScale(_CS.playerScale,_CS.playerScale);
        playerRole.getComponent(cc.Sprite).spriteFrame = aniArr[0];
		playerRole.getComponent(cc.Animation).addClip(_GRM.createAniClip(aniArr,'walk',cc.WrapMode.Loop));
        playerRole.getComponent(cc.Animation).addClip(_GRM.createAniClip(attackAniArr,'attack',cc.WrapMode.Normal));
        playerRole.getComponent(cc.Animation).addClip(_GRM.createAniClip(weakAniArr,'weak',cc.WrapMode.Loop));
        

        if(playerNodeObj.isnew){
            //playerbtn.on(cc.Node.EventType.TOUCH_START, _MFN.playerNodeTouch, playerNode); 
        }

        playerNode.getChildByName('role').removeAllChildren();

        selectedNode.active = false;

        _MFN.refreshPlayerNode(playerNode,player);

        return playerNode;

    },

    //切换动画
    switchAni:function(playerNode,ani){



        var playerRole = playerNode.getChildByName('role');

        var aniObj = _GRM.getAttackFrame(ani);
        var aniArr = aniObj.walk;
        var attackAniArr = aniObj.attack;
        var weakAniArr = aniObj.weak;

        //console.log('变身:',aniObj);

        playerRole.getComponent(cc.Animation).addClip(_GRM.createAniClip(aniArr,'walk',cc.WrapMode.Loop));
        playerRole.getComponent(cc.Animation).addClip(_GRM.createAniClip(attackAniArr,'attack',cc.WrapMode.Normal));
        playerRole.getComponent(cc.Animation).addClip(_GRM.createAniClip(weakAniArr,'weak',cc.WrapMode.Loop));
    }


}